package com.industrial.governance.util;

import java.util.ArrayList;
import java.util.List;

public class PageUtils {

    public static <T> PageResult<T> paginateList(List<T> data, int pagenum, int pageSize) {
        int startIdx = (pagenum - 1) * pageSize;
        int endIdx = Math.min(startIdx + pageSize, data.size());

        if (startIdx >= data.size()) {
            return new PageResult(new ArrayList<>(), 0);
        }

        List<T> paginatedData = data.subList(startIdx, endIdx);
        return new PageResult(paginatedData, data.size());
    }
}
